<template>
  <div class="finance-apply-page">
    <front-header />
    <div class="main-content">
      <div class="apply-illustration">
        <img src="@/assets/imgs/img2.png" alt="finance-illust" class="illust-image" />
      </div>
      <el-card class="apply-card" shadow="hover">
        <div class="section-header">
          <i class="el-icon-money section-icon"></i>
          <span class="section-title">融资申请</span>
        </div>
        <div class="section-divider"></div>
        <el-form :model="form" :rules="rules" ref="form" label-width="80px" class="finance-apply-form">
          <el-form-item label="金额" prop="amount">
            <el-input v-model.number="form.amount" placeholder="请输入融资金额" prefix-icon="el-icon-money"></el-input>
          </el-form-item>
          <el-form-item label="说明" prop="reason">
            <el-input v-model="form.reason" type="textarea" :rows="3" placeholder="请填写融资用途或说明"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="success" class="apply-btn" @click="onSubmit">提交申请</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <front-footer />
  </div>
</template>

<script>
import request from '@/utils/request'
import FrontHeader from "@/components/front/FrontHeader.vue";
import FrontFooter from "@/components/front/FrontFooter.vue";

export default {
  name: 'FinanceApply',
  components: { FrontFooter, FrontHeader },
  data() {
    return {
      form: {
        amount: '',
        reason: ''
      },
      rules: {
        amount: [
          { required: true, message: '请输入融资金额', trigger: 'blur' },
          { type: 'number', min: 1, message: '金额需大于0', trigger: 'blur' }
        ],
        reason: [
          { required: true, message: '请填写说明', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate(async valid => {
        if (!valid) return;
        const user = JSON.parse(localStorage.getItem('frontUser') || '{}');
        if (!user.id) {
          this.$message.warning('请先登录');
          this.$router.push('/login');
          return;
        }
        const data = {
          userId: user.id,
          username: user.username,
          amount: this.form.amount,
          reason: this.form.reason
        };
        try {
          await request.post('/finance/apply', data);
          this.$message.success('申请已提交，等待审核');
          this.form.amount = '';
          this.form.reason = '';
        } catch (e) {
          this.$message.error('提交失败');
        }
      });
    }
  }
}
</script>

<style scoped>
.finance-apply-page {
  min-height: 100vh;
  background: #f9f9f9;
  display: block;

  flex-direction: column;
  color: #333333;
  height: 100vh;
  max-height: 100%;
}
.main-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px 0 32px 0;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  height: 60vh;
}
.apply-illustration {
  flex: 0 0 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 48px;
}
.illust-image {
  width: 220px;
  max-width: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  background: #ffffff;
  border: 1px solid #eaeaea;
  filter: brightness(1) contrast(1);
  transition: all 0.3s ease;
}
.illust-image:hover {
  transform: scale(1.03);
  filter: brightness(1.05) contrast(1.05);
  box-shadow: 0 12px 36px rgba(76, 175, 80, 0.2);
}
.apply-card {
  flex: 1 1 400px;
  max-width: 420px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 36px 32px 28px 32px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid #eaeaea;
}
.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.section-icon {
  font-size: 28px;
  color: #4caf50;
  margin-right: 12px;
}
.section-title {
  font-size: 24px;
  color: #333333;
  font-weight: 600;
  letter-spacing: 1px;
}
.section-divider {
  height: 2px;
  background: linear-gradient(90deg, #4caf50 0%, #81c784 100%);
  border-radius: 1px;
  margin-bottom: 28px;
}
.finance-apply-form {
  margin-top: 0;
}
.finance-apply-form :deep(.el-form-item__label) {
  color: #333333;
}
.finance-apply-form :deep(.el-input__inner) {
  background: #ffffff;
  border: 1px solid #dcdfe6;
  color: #333333;
  border-radius: 8px;
  height: 44px;
}
.finance-apply-form :deep(.el-input__inner:focus) {
  border-color: #4caf50;
}
.finance-apply-form :deep(.el-textarea__inner) {
  background: #ffffff;
  border: 1px solid #dcdfe6;
  color: #333333;
  border-radius: 8px;
  min-height: 120px;
}
.finance-apply-form :deep(.el-textarea__inner:focus) {
  border-color: #4caf50;
}
.apply-btn {
  width: 100%;
  height: 44px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  background: linear-gradient(90deg, #4caf50 0%, #81c784 100%);
  color: #fff;
  border: none;
  transition: all 0.3s ease;
}
.apply-btn:hover {
  background: linear-gradient(90deg, #3b9c3f 0%, #6ebb71 100%);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.3);
  transform: translateY(-2px);
}
@media (max-width: 900px) {
  .main-content {
    flex-direction: column;
    padding: 32px 0 24px 0;
    max-width: 100%;
  }
  .apply-illustration {
    margin: 0 0 24px 0;
    justify-content: center;
  }
  .apply-card {
    max-width: 95vw;
    min-width: 0;
    padding: 28px 12px 20px 12px;
  }
}
</style> 